package logger

import (
	"bytes"
	"log"
	"os"
)

var (
	buf    *bytes.Buffer
	logger *log.Logger
)

func init() {
	buf = &bytes.Buffer{}
	// logger = log.New(buf, "", log.LstdFlags)
	logger = log.New(os.Stderr, "", log.LstdFlags)
	logger.Println("start")
	log.Println("")
}

func Logger() *log.Logger {
	return logger
}

func Buf() string {
	return buf.String()
}

// Errorfn Log errors with format
func Errorfn(fn string, err error) {
	logger.Printf("[%s]: %v", fn, err)
}

// Info Log
func Info(args ...interface{}) {
	logger.Println(args...)
}

// Infof Log
func Infof(format string, args ...interface{}) {
	logger.Printf(format, args...)
}

// Warn Log
func Warn(args ...interface{}) {
	logger.Println(args...)
}

// Warnf Log
func Warnf(format string, args ...interface{}) {
	logger.Printf(format, args...)
}

// Panic Log
func Panic(args ...interface{}) {
	logger.Panicln(args...)
}

// Panicf Log
func Panicf(format string, args ...interface{}) {
	logger.Panicf(format, args...)
}

// Error Log
func Error(args ...interface{}) {
	logger.Println(args...)
}

// Errorf Log
func Errorf(format string, args ...interface{}) {
	logger.Printf(format, args...)
}

// Fatal Log
func Fatal(args ...interface{}) {
	logger.Fatalln(args...)
}

// Fatalf Log
func Fatalf(format string, args ...interface{}) {
	logger.Fatalf(format, args...)
}
